﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ParamiliarControls
{
    public partial class frmNotify : Form
    {
        private int startPosX, startPosY, startHeight;
        private string subject, message;
        private Color subjectcolor;

        public enum ErrorType
        {
            error,
            warning,
            info, 
            success
        }
        

        public frmNotify(ErrorType type, string title, string content)
        {
            subject = title;
            message = content;
            switch (type)
            {
                case ErrorType.error:
                    this.BackColor = Color.FromArgb(250, 205, 206);
                    this.TransparencyKey = Color.FromArgb(250, 205, 206);
                    this.BackgroundImage = Properties.Resources.errorWindow;
                    subjectcolor = Color.FromArgb(153, 30, 5);
                    break;
                case ErrorType.warning:
                    this.BackColor = Color.FromArgb(249, 247, 198);
                    this.TransparencyKey = Color.FromArgb(249, 247, 198);
                    this.BackgroundImage = Properties.Resources.warningWindow;
                    subjectcolor = Color.FromArgb(208, 122, 1);
                    break;
                case ErrorType.info:
                    this.BackColor = Color.FromArgb(214, 231, 250);
                    this.TransparencyKey = Color.FromArgb(214, 231, 250);
                    this.BackgroundImage = Properties.Resources.infoWindow;
                    subjectcolor = Color.FromArgb(8, 72, 160);
                    break;
                default: //success
                    this.BackColor = Color.FromArgb(207, 250, 200);
                    this.TransparencyKey = Color.FromArgb(207, 250, 200);
                    this.BackgroundImage = Properties.Resources.successWindow;
                    subjectcolor = Color.FromArgb(58, 152, 5);
                    break;

            }

            setupForm();            
        }

        protected void setupForm(){
            InitializeComponent();
            lblTitle.Text = subject;
            lblTitle.ForeColor = subjectcolor;
            lblTitle.Location = new Point(this.ClientSize.Width / 2 - lblTitle.Size.Width / 2, lblTitle.Location.Y);

            lblContent.BackColor = Color.FromArgb(this.BackColor.R+5, this.BackColor.G+5, this.BackColor.B+5);           
            lblContent.Text = message;
            lblTitle.Focus();
            
            timer1.Interval = 10;
            timer1.Tick += timer_Tick;
        }
        protected override void OnLoad(EventArgs e)
        {
            // Move window out of screen
            startPosX = Screen.PrimaryScreen.WorkingArea.Width - Width;
            startPosY = Screen.PrimaryScreen.WorkingArea.Height;
            startHeight = Height;
            Height = 0;
            SetDesktopLocation(startPosX, startPosY);
            base.OnLoad(e);
            timer1.Start();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            Height += 5;
            startPosY -= 5;
            SetDesktopLocation(startPosX, startPosY);
            if (Height >= startHeight)
            {
                timer1.Stop();
                timer2.Interval = 5000;
                timer2.Start();
                SetDesktopLocation(startPosX, startPosY);
            }
        }
        private void stopTimer()
        {
            timer2.Stop();
        }
        private void startTimer()
        {
            timer2.Start();
        }
        private void frmNotify_MouseHover(object sender, EventArgs e)
        {
            stopTimer();
        }
        private void frmNotify_MouseLeave(object sender, EventArgs e)
        {
            startTimer();
        }
        private void timer2_Tick(object sender, EventArgs e)
        {
            timer3.Interval = 10;
            timer3.Start();
        }
        private void timer3_Tick(object sender, EventArgs e)
        {
            Height -= 5;
            startPosY += 5;
            //Console.WriteLine(Height.ToString());
            if (Height <= 5)
            {
                timer3.Stop();                            
                this.Close();
            }
            else
            {
                SetDesktopLocation(startPosX, startPosY);
            }
        }

        private void frmNotify_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void lblTitle_MouseHover(object sender, EventArgs e)
        {
            stopTimer();
        }

        private void lblTitle_MouseLeave(object sender, EventArgs e)
        {
            startTimer();
        }

        private void lblContent_MouseHover(object sender, EventArgs e)
        {
            stopTimer();
        }

        private void lblContent_MouseLeave(object sender, EventArgs e)
        {
            startTimer();
        }

    }
}
